package com.yiyuzi.admin.common.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author yiyuzi
 * @date 2021/5/12 22:18
 */

public class UserUtils {
    public static String getMD5Str(String str){
        return MD5(MD5(str));
    }

    public static boolean checkPwd(String pwd1, String pwd2){
        return getMD5Str(pwd1).equals(getMD5Str(pwd2));
    }

    private static String MD5(String str) {
        byte[] digest = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            digest  = md5.digest(str.getBytes("utf-8"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //16是表示转换为16进制数
        return new BigInteger(1, digest).toString(16);
    }
}
